﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Quan_Ly_Phong_Kham_co_len_em.CheckLogin
{
    public static class CheckLogin
    {
        public static DataTable Select(string _user, string _pass)
        {
            SqlConnection ketnoi = new SqlConnection("Data Source=NGUYENTY-PC\\SQLEXPRESS;Initial Catalog=QL_PHONGKHAM;Integrated Security=True");
            ketnoi.Open();
            SqlCommand cmd = new SqlCommand("Select matkhau,VaitroID from TAIKHOAN where taikhoan ='" + _user + "' ", ketnoi);
            DataTable dt = new DataTable();
            dt.Load(cmd.ExecuteReader());
            return dt;
        }

        public static bool Check(string _user,string _pass)
        {
            try
            {
                DataTable dtb = Select(_user, _pass);
                if (dtb == null)
                    return false;

                string pass = dtb.Rows[0]["Matkhau"] + "";
                if (pass != _pass)
                    return false;
                return true;
            }
            catch { return false; }
        }

        public static int Role(string _user, string _pass)
        {
            bool check = Check(_user, _pass);
            DataTable dtb = Select(_user, _pass);
            int role = 0;
            if (check)
                 role = Convert.ToInt32(dtb.Rows[0]["VaitroID"]);
            return role;
        }

    }
}
